//###############
// FILE : LogicOperator.java
// WRITER : Lior Zimmerman liorz06 066462300
// WRITER : Ohad Dan ohad_dan 036767960
// EXERCISE : oop ex3 2008
// DESCRIPTION: Representation of a logic operator.
//###############
package oop.ex3.fileSearchModel.filters;

import java.io.File;
import java.util.ArrayList;

import oop.ex3.fileSearchModel.parser.exceptions.*;

/**
 * Representation of a logic operator.
 */
public abstract class LogicOperator implements Conditionable,Cloneable{
  
    //***********************************************************************
    //  Data members :                                                      *
    //***********************************************************************
    protected Conditionable _leftTerm,_rightTerm;
    protected STATUS _status;
    //***********************************************************************
    //  Methods :                                                           *
    //***********************************************************************
    /**
     * Constructs a new logic operator.
     */
    public LogicOperator(){
        _status = STATUS.UNKNOWN;
    }
    /**
     * Constructs a new logic operator.
     * @param right Right child.
     * @param left Left child.
     * @param status Condition's status.
     */
    public LogicOperator( Conditionable right, Conditionable left,
            STATUS status) {
        _status = status;
        _leftTerm = left;
        _rightTerm = right;
    }
    /**
     * Set the right child.
     * @param op Right child to be set.
     * @throws ParsingException In case of error parsing op. 
     */
    public void setRightChild( Conditionable op ) throws ParsingException {
        _rightTerm = op;
    }
    /**
     * Set the left child.
     * @param op Left child to be set.
     * ParsingException In case of error parsing op. 
     */
    public void setLeftChild( Conditionable op ) throws ParsingException {
        _leftTerm = op;
    }
    /**
     * Sets the status of the condition to the given status.
     * @param status Condition's value.
     */
    public void setCondition( STATUS status ) {
        _status = status;
    }
    
    /**
     * Resets recursively the data of the logic operator and all children. 
     * @param resetData Data info for reset.
     * @param source Source directory.
     */
    public void reset(File resetData,String source){
        setCondition(STATUS.UNKNOWN);
        if (_leftTerm != null){
            _leftTerm.reset(resetData,source);
        }
        if (_rightTerm != null){
            _rightTerm.reset(resetData,source);
        }
    }
    /**
     * Returns a list with all the byte filters.
     * @return A list with all the byte filters.
     */
    public ArrayList<Filter> getByteList(){
        ArrayList<Filter> list = new ArrayList<Filter>();
        if  (_leftTerm != null){
            list.addAll(_leftTerm.getByteList());
        }
        if  (_rightTerm != null){
            list.addAll(_rightTerm.getByteList());
        }
        return list;
    }
    /**
     * Returns a list with all the byte filters.
     * @return A list with all the byte filters.
     */
    public ArrayList<Filter> getTextList(){
        ArrayList<Filter> list = new ArrayList<Filter>();
        if  (_leftTerm != null){
            list.addAll(_leftTerm.getTextList());
        }
        if  (_rightTerm != null){
            list.addAll(_rightTerm.getTextList());
        }
        return list;
    }
    /**
	 *  Clones the object - return a new object with same properties.
	 */
    public abstract LogicOperator clone();
    /**
     * Calculates filter's condition.
     */
    public void calculate(){}
}
